package com.sims.action.general;

import org.springframework.beans.factory.annotation.Autowired;

import com.sims.bean.Manager;
import com.sims.bean.Student;
import com.sims.bean.StudentPosition;
import com.sims.bean.Teacher;
import com.sims.service.ManagerService;
import com.sims.service.StudentService;
import com.sims.service.TeacherService;
import com.sims.util.ActionEnhanced;
import com.sims.util.Constant;
import com.sims.util.HttpSessionUtil;

@SuppressWarnings("serial")
public class GoBackIndexAction extends ActionEnhanced{
	
	private Student student = new Student();
	private StudentPosition studentPosition = new StudentPosition();
	private Teacher teacher = new Teacher();
	private Manager manager = new Manager();
	
	@Autowired
	private StudentService studentService;
	@Autowired
	private TeacherService teacherService;
	@Autowired
	private ManagerService managerService;
	
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	public Teacher getTeacher() {
		return teacher;
	}
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	public Manager getManager() {
		return manager;
	}
	public void setManager(Manager manager) {
		this.manager = manager;
	}
	
	@Override
	public String execute() {
		
		if(HttpSessionUtil.getUserType().equals(Constant.STUDENT)){
			student.setSid(HttpSessionUtil.getUserId());
			result = studentService.findStudentBasicInfo(student, studentPosition);
			if (result.containsKey(SUCCESS))
				return "studentIndex";
			else return ERROR;
		}
		
		if(HttpSessionUtil.getUserType().equals(Constant.TEACHER)){
			teacher.setTid(HttpSessionUtil.getUserId());
			result = teacherService.findTeacherBasicInfo(teacher);
			if (result.containsKey(SUCCESS))
				return "teacherIndex";
			else return ERROR;
		}
		
		if(HttpSessionUtil.getUserType().equals(Constant.MANAGER)) {
			return "managerIndex";
		}
		return ERROR;
	}
}
